<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Topic;
use Auth;
use DB;

class UserController extends Controller
{
  
    public function add(){
        return view('add');
    }

    public function not(){
        return view('not');
    }

    public function sea(Request $req){
        if($req->input('keywords') == ''){

                 return view('seaErr');

        }else{
            $topic = new Topic();
            $rs = $req->input('keywords');

            $data = $topic->where('title','like',"%$rs%")->paginate(2);

               return view('index',['data'=>$data]);

        }

    }

    public function seaErr(){

            return view('seaErr');
    }

    public function prev(){
        $topic = new Topic();
        $user = Auth::user();
        $data = $topic->where('uid',$user->uid)->get()->toarray();

        return view('prev',['data'=>$data]);
    }

    public function up($tid){

        $topic = new Topic();
        $data = $topic->getTopic($tid);
//      dump($data);
        return view('upVote',['data'=>$data]);

    }

    public function delVote($tid){

        $topic = new Topic();
        Topic::where('topics.tid',$tid)->join('selects','topics.tid','=','selects.tid')->delete();
        DB::table('votes')->where('tid',$tid)->delete();
        return redirect('prev');
    }


}
